package com.fingerth.crawler.utils.stati

import android.content.Context

object S {
    private var SYS_WIDTH = 0
    private var SYS_HEIGHT = 0
    private var STATUS_BAR_HEIGHT = 0
    private var NAVIGATION_BAR_HEIGHT = 0

    fun getSysWidth(activity: Context?): Int {
        if (SYS_WIDTH <= 0) SYS_WIDTH = activity?.resources?.displayMetrics?.widthPixels ?: 0
        return SYS_WIDTH
    }

    fun getSysHeight(activity: Context?): Int {
        if (SYS_HEIGHT <= 0) SYS_HEIGHT = activity?.resources?.displayMetrics?.heightPixels ?: 0
        return SYS_HEIGHT
    }

    fun getStatusBarHeight(context: Context?): Int {
        if (STATUS_BAR_HEIGHT <= 0) {
            context?.let { c ->
                val resourceId = c.resources.getIdentifier("status_bar_height", "dimen", "android")
                if (resourceId > 0) STATUS_BAR_HEIGHT = c.resources.getDimensionPixelSize(resourceId)
            }
        }
        return STATUS_BAR_HEIGHT
    }

    /**
     * 获取导航栏高度
     */
    fun getNavigationBarHeight(c: Context?): Int {
        if (NAVIGATION_BAR_HEIGHT <= 0) {
            c?.let { context ->
                val rid = context.resources.getIdentifier("config_showNavigationBar", "bool", "android")
                if (rid != 0) {
                    val resourceId = context.resources.getIdentifier("navigation_bar_height", "dimen", "android")
                    NAVIGATION_BAR_HEIGHT = context.resources.getDimensionPixelSize(resourceId)
                }
            }
        }
        return NAVIGATION_BAR_HEIGHT
    }

}